package com.fxc.factory;

import com.fxc.api.EmployeeRemoteService;
import com.fxc.entity.Employee;
import com.fxc.util.ResultEntity;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *  实现Consumer端服务降级功能
 *  实现FallbackFactory接口时要传入@FeignClient注解标记的接口类型
 *  在create（）方法中返回@FeignClient标记的接口类型对象，当Provider调用失败后，会执行这个对象的对应的方法
 *  这个类必须使用@Component注解 当前类的对象加入到IOC容器，当然当前类必须能够扫描到
 */
@Component
public class MyFallBackFactory implements FallbackFactory<EmployeeRemoteService> {
    @Override
    public EmployeeRemoteService create(Throwable throwable) {
        return new EmployeeRemoteService( ) {
            @Override
            public Employee getEmployeeRemote() {
                return null;
            }

            @Override
            public Employee getEmployeeById(Integer empId) {
                return null;
            }

            @Override
            public Employee saveEmploy(Employee employee) {
                return null;
            }

            @Override
            public List<Employee> getListEmpListRemote(String keyword) {
                return null;
            }

            @Override
            public ResultEntity<Employee> getEmpWithCircuitBreaker(String signal) {
                return ResultEntity.failed("降级机制生效" + throwable.getMessage());
            }
        };
    }
}
